﻿<Window x:Class="remes.XDraw.XDrawWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:sys="clr-namespace:System;assembly=mscorlib"
        xmlns:local="clr-namespace:remes.XDraw"
        Title="XDraw" Height="600" Width="800"
        x:Name="xDrawWindow" x:Uid="xDraw.Window"
    Loaded="Window_Loaded">
  <Grid>
    <Grid.Resources>
      <ObjectDataProvider x:Key="penLineCapValues"
                      MethodName="GetValues" 
                      ObjectType="{x:Type sys:Enum}">
        <ObjectDataProvider.MethodParameters>
          <x:Type TypeName="PenLineCap"/>
        </ObjectDataProvider.MethodParameters>
      </ObjectDataProvider>
      
      <ObjectDataProvider x:Key="penLineJoinValues"
                      MethodName="GetValues" 
                      ObjectType="{x:Type sys:Enum}">
        <ObjectDataProvider.MethodParameters>
          <x:Type TypeName="PenLineJoin" />
        </ObjectDataProvider.MethodParameters>
      </ObjectDataProvider>
      
      <ObjectDataProvider x:Key="sweepDirectionValues"
                                              MethodName="GetValues" 
                                              ObjectType="{x:Type sys:Enum}">
        <ObjectDataProvider.MethodParameters>
          <x:Type TypeName="SweepDirection"/>
        </ObjectDataProvider.MethodParameters>
      </ObjectDataProvider>
    </Grid.Resources>

    <Grid.RowDefinitions>
      <RowDefinition Height="Auto"/>
      <RowDefinition Height="Auto"/>
      <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
    <Menu Grid.Row="0">
      <MenuItem Header="_File" x:Uid="menu.File">
        <MenuItem Header="_New drawing" x:Uid="menu.File.New" Click="btnClear_Click">
          <MenuItem.Icon>
            <Image Height="16" Width="16" Stretch="Uniform" 
                   Source="{StaticResource NewDrawingImage}"/>
          </MenuItem.Icon>
        </MenuItem>
        <MenuItem Header="_Load" x:Uid="menu.File.Load" Click="btnLoad_Click">
          <MenuItem.Icon>
            <Image Height="16" Width="16" Stretch="Uniform" 
                   Source="{StaticResource LoadDrawingImage}"/>
          </MenuItem.Icon>
        </MenuItem>
        <MenuItem Header="_Save" x:Uid="menu.File.Save" Click="btnSave_Click">
          <MenuItem.Icon>
            <Image Height="16" Width="16" Stretch="Uniform" 
                   Source="{StaticResource SaveDrawingImage}"/>
          </MenuItem.Icon>
        </MenuItem>
        <Separator/>
        <MenuItem Header="_Exit" x:Name="miExit" x:Uid="menu.File.Exit" Click="Exit_Click"/>
      </MenuItem>
      
      <MenuItem Header="_View" x:Uid="menu.View">
        <MenuItem Header="_Small buttons" IsCheckable="True" IsChecked="False" 
                  x:Name="miSmallButtons" x:Uid="menu.View.SmallButtons" Click="miSmallButtons_Click"/>
        <MenuItem Header="_Large buttons" IsCheckable="True" IsChecked="True" 
                  x:Name="miLargeButtons" x:Uid="menu.View.LargeButtons" Click="miLargeButtons_Click"/>
      </MenuItem>

      <MenuItem Header="_Tools" x:Uid="menu.Tools">
        <MenuItem Header="_Delete shape" x:Uid="menu.Tools.DeleteShape" Click="btnDeleteShape_Click">
          <MenuItem.Icon>
            <Image Height="16" Width="16" Stretch="Uniform" 
                   Source="{StaticResource DeleteShapeImage}"/>
          </MenuItem.Icon>
        </MenuItem>
        <Separator/>
        <MenuItem Header="_Select shape" x:Uid="menu.Tools.SelectShape" Click="btnSelect_Click"
                  x:Name="miSelect" IsCheckable="True">
          <MenuItem.Icon>
            <Image Height="16" Width="16" Stretch="Uniform" 
                   Source="{StaticResource SelectToolImage}"/>
          </MenuItem.Icon>
        </MenuItem>
        <MenuItem Header="_Edit shape" x:Uid="menu.Tools.EditShape" Click="btnEdit_Click"
                x:Name="miEdit" IsCheckable="True">
          <MenuItem.Icon>
            <Image Height="16" Width="16" Stretch="Uniform" 
                 Source="{StaticResource EditToolImage}"/>
          </MenuItem.Icon>
        </MenuItem>
        <Separator/>
        <MenuItem Header="_New line" x:Uid="menu.Tools.NewLine" Click="btnNewLine_Click"
                  x:Name="miNewLine" IsCheckable="True">
          <MenuItem.Icon>
            <Image Height="16" Width="16" Stretch="Uniform" 
                   Source="{StaticResource LineToolImage}"/>
          </MenuItem.Icon>
        </MenuItem>
        <MenuItem Header="_New rectangle" x:Uid="menu.Tools.NewRectangle" Click="btnNewRect_Click"
                  x:Name="miNewRect" IsCheckable="True">
          <MenuItem.Icon>
            <Image Height="16" Width="16" Stretch="Uniform" 
                   Source="{StaticResource RectangleToolImage}"/>
          </MenuItem.Icon>
        </MenuItem>
        <MenuItem Header="_New ellipse" x:Uid="menu.Tools.NewEllipse" Click="btnNewEllipse_Click"
                  x:Name="miNewEllipse" IsCheckable="True">
          <MenuItem.Icon>
            <Image Height="16" Width="16" Stretch="Uniform" 
                   Source="{StaticResource EllipseToolImage}"/>
          </MenuItem.Icon>
        </MenuItem>
        <MenuItem Header="_New path" x:Uid="menu.Tools.NewLine" Click="btnNewPath_Click"
                  x:Name="miNewPath" IsCheckable="True">
          <MenuItem.Icon>
            <Image Height="16" Width="16" Stretch="Uniform" 
                   Source="{StaticResource PathToolImage}"/>
          </MenuItem.Icon>
        </MenuItem>
      </MenuItem>
      
      <MenuItem Header="_Help" x:Uid="menu.Help">
        <MenuItem Header="_About XDraw ..." x:Name="miAbout" x:Uid="menu.Help.About" Click="miAbout_Click"/>
      </MenuItem>
    </Menu>

    <ToolBarTray Grid.Row="1">
      <ToolBar Band="0">
        <Button Width="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}, Path=ToolbarButtonSize}" 
                Height="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}, Path=ToolbarButtonSize}" 
                ToolTip="Load drawing" x:Name="btnLoad" x:Uid="toolbar.File.Load" Click="btnLoad_Click">
          <Button.Content>
            <Image Source="{StaticResource LoadDrawingImage}"/>
          </Button.Content>
        </Button>
        <Button Width="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}, Path=ToolbarButtonSize}" 
                Height="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}, Path=ToolbarButtonSize}" 
                ToolTip="Save drawing" x:Name="btnSave" x:Uid="toolbar.File.Save" Click="btnSave_Click">
        <Button.Content>
            <Image Source="{StaticResource SaveDrawingImage}"/>
          </Button.Content>
        </Button>
        <Separator/>
        <Button Width="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}, Path=ToolbarButtonSize}" 
                Height="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}, Path=ToolbarButtonSize}" 
                ToolTip="New drawing" x:Name="btnClear" x:Uid="toolbar.File.Clear" Click="btnClear_Click">
          <Button.Content>
            <Image Source="{StaticResource NewDrawingImage}"/>
          </Button.Content>
        </Button>
      </ToolBar>
      <ToolBar Band="0">
        <Button Width="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}, Path=ToolbarButtonSize}" 
                Height="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}, Path=ToolbarButtonSize}" 
                ToolTip="Delete shape" x:Name="btnDeleteShape" x:Uid="toolbar.DeleteShape" Click="btnDeleteShape_Click">
          <Button.Content>
            <Image Source="{StaticResource DeleteShapeImage}"/>
          </Button.Content>
        </Button>
        <Separator/>
        <CheckBox Width="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}, Path=ToolbarButtonSize}" 
                  Height="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}, Path=ToolbarButtonSize}" 
                  ToolTip="Select shape" x:Name="btnSelect" x:Uid="toolbar.Mode.Select" Click="btnSelect_Click">
          <CheckBox.Content>
            <Image Source="{StaticResource SelectToolImage}"/>
          </CheckBox.Content>
        </CheckBox>
        <CheckBox Width="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}, Path=ToolbarButtonSize}" 
                  Height="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}, Path=ToolbarButtonSize}" 
                  ToolTip="Edit shape" x:Name="btnEdit" x:Uid="toolbar.Mode.Edit" Click="btnEdit_Click">
          <CheckBox.Content>
            <Image Source="{StaticResource EditToolImage}"/>
          </CheckBox.Content>
        </CheckBox>
        <Separator/>
        <CheckBox Width="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}, Path=ToolbarButtonSize}" 
                  Height="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}, Path=ToolbarButtonSize}" 
                  ToolTip="New line" x:Name="btnLine" x:Uid="toolbar.Mode.Line" Click="btnNewLine_Click">
          <CheckBox.Content>
            <Image Source="{StaticResource LineToolImage}"/>
          </CheckBox.Content>
        </CheckBox>
        <CheckBox Width="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}, Path=ToolbarButtonSize}" 
                  Height="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}, Path=ToolbarButtonSize}" 
                  ToolTip="New rectangle" x:Name="btnRect" x:Uid="toolbar.Mode.Rectangle" Click="btnNewRect_Click">
          <CheckBox.Content>
            <Image Source="{StaticResource RectangleToolImage}"/>
          </CheckBox.Content>
        </CheckBox>
        <CheckBox Width="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}, Path=ToolbarButtonSize}" 
                  Height="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}, Path=ToolbarButtonSize}" 
                  ToolTip="New ellipse" x:Name="btnEllipse" x:Uid="toolbar.Mode.Ellipse" Click="btnNewEllipse_Click">
          <CheckBox.Content>
            <Image Source="{StaticResource EllipseToolImage}"/>
          </CheckBox.Content>
        </CheckBox>
        <CheckBox Width="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}, Path=ToolbarButtonSize}" 
                  Height="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}, Path=ToolbarButtonSize}" 
                  ToolTip="new path" x:Name="btnPath" x:Uid="toolbar.Mode.Path" Click="btnNewPath_Click">
          <CheckBox.Content>
            <Image Source="{StaticResource PathToolImage}"/>
          </CheckBox.Content>
        </CheckBox>
      </ToolBar>
    </ToolBarTray>

    <Grid Grid.Row="2">
      <Grid.ColumnDefinitions>
        <ColumnDefinition Width="200"/>
        <ColumnDefinition Width="*"/>
      </Grid.ColumnDefinitions>

      <GridSplitter Grid.Column="0" HorizontalAlignment="Right" Width="3"/>
      <ScrollViewer VerticalScrollBarVisibility="Auto" Margin="0,0,3,0">
        <StackPanel Grid.Column="0" Orientation="Vertical"
                    DataContext="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}, Path=Drawing.SelectedShape}">
          <Border BorderBrush="Blue" BorderThickness="1" CornerRadius="5" Margin="1">
            <Expander IsExpanded="True">
              <Expander.Header>
                <Grid>
                  <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="*"/>
                  </Grid.ColumnDefinitions>
                  <TextBlock Grid.Column="0" Text="Stroke" VerticalAlignment="Center" Margin="3,0"/>
                  <Line Grid.Column="1" X1="0" Y1="0" X2="1" Y2="0"  VerticalAlignment="Center" Margin="3,0"
                        Stretch="Fill"
                        Stroke="{Binding Path.Stroke, Mode=TwoWay}" 
                        StrokeThickness="{Binding Path.StrokeThickness, Mode=TwoWay}"/>
                </Grid>
              </Expander.Header>
              <StackPanel Orientation="Vertical">
                <Grid Margin="3">
                  <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="*"/>
                  </Grid.ColumnDefinitions>
                  <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                  </Grid.RowDefinitions>
                  <TextBlock Grid.Row="0" Grid.Column="0" Text="Thickness" Margin="3,0" VerticalAlignment="Center"/>
                  <TextBox Grid.Row="0" Grid.Column="1" Text="{Binding Path.StrokeThickness}" Margin="3,0"/>
                  <TextBlock Grid.Row="1" Grid.Column="0" Text="Dash" Margin="3,0" VerticalAlignment="Center"/>
                  <TextBox Grid.Row="1" Grid.Column="1" Text="{Binding StrokeDash}" Margin="3,0"/>
                  <TextBlock Grid.Row="2" Grid.Column="0" Text="Dash cap" Margin="3,0" VerticalAlignment="Center"/>
                  <ComboBox Grid.Row="2" Grid.Column="1" Margin="3,0"
                            ItemsSource="{Binding Source={StaticResource penLineCapValues}}"
                            SelectedItem="{Binding Path.StrokeDashCap}"/>
                  <TextBlock Grid.Row="3" Grid.Column="0" Text="Dash offset" Margin="3,0" VerticalAlignment="Center"/>
                  <TextBox Grid.Row="3" Grid.Column="1" Text="{Binding Path.StrokeDashOffset}" Margin="3,0"/>
                  <TextBlock Grid.Row="4" Grid.Column="0" Text="Line caps" Margin="3,0" VerticalAlignment="Center"/>
                  <Grid Grid.Row="4" Grid.Column="1" >
                    <Grid.ColumnDefinitions>
                      <ColumnDefinition Width="*"/>
                      <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <ComboBox Grid.Column="0" Margin="3,0"
                            ItemsSource="{Binding Source={StaticResource penLineCapValues}}"
                            SelectedItem="{Binding Path.StrokeStartLineCap}"/>
                    <ComboBox Grid.Column="1" Margin="3,0"
                            ItemsSource="{Binding Source={StaticResource penLineCapValues}}"
                            SelectedItem="{Binding Path.StrokeEndLineCap}"/>
                  </Grid>
                  <TextBlock Grid.Row="5" Grid.Column="0" Text="Line join" Margin="3,0" VerticalAlignment="Center"/>
                  <ComboBox Grid.Row="5" Grid.Column="1" Margin="3,0"
                            ItemsSource="{Binding Source={StaticResource penLineJoinValues}}"
                            SelectedItem="{Binding Path.StrokeLineJoin}"/>
                  <TextBlock Grid.Row="6" Grid.Column="0" Text="Miter limit" Margin="3,0" VerticalAlignment="Center"/>
                  <TextBox Grid.Row="6" Grid.Column="1" Text="{Binding Path.StrokeMiterLimit}" Margin="3,0"/>
                </Grid>

                <Rectangle Height="2">
                  <Rectangle.Fill>
                    <LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
                      <GradientStop Color="Blue" Offset="0"/>
                      <GradientStop Color="White" Offset="0.5"/>
                      <GradientStop Color="Blue" Offset="1"/>
                    </LinearGradientBrush>
                  </Rectangle.Fill>
                </Rectangle>
                <local:BrushEditControl Grid.Row="0" Grid.ColumnSpan="2" 
                                        IsExpanded="True"
                                        Text="Brush" Brush="{Binding Path.Stroke, Mode=TwoWay}"/>
              </StackPanel>
            </Expander>
          </Border>

          <Border BorderBrush="Blue" BorderThickness="1" CornerRadius="5" Margin="1">
            <local:BrushEditControl Grid.Row="0" Grid.ColumnSpan="2" 
                                        IsExpanded="True"
                                        Text="Fill brush" Brush="{Binding Path.Fill, Mode=TwoWay}"/>
          </Border>

          <Border BorderBrush="Blue" BorderThickness="1" CornerRadius="5" Margin="1">
            <Border.Resources>
              <DataTemplate DataType="{x:Type local:XDrawingLine}">
                <Grid>
                  <Grid.Resources>
                    <Style TargetType="{x:Type TextBlock}">
                      <Setter Property="Margin" Value="3,1"/>
                      <Setter Property="VerticalAlignment" Value="Center"/>
                    </Style>
                    <Style TargetType="{x:Type TextBox}">
                      <Setter Property="Margin" Value="3,1"/>
                      <Setter Property="VerticalAlignment" Value="Center"/>
                    </Style>
                  </Grid.Resources>
                  <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" SharedSizeGroup="col0"/>
                    <ColumnDefinition Width="*" SharedSizeGroup="col1"/>
                  </Grid.ColumnDefinitions>
                  <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                  </Grid.RowDefinitions>

                  <TextBlock Grid.Row="0" Grid.Column="0" Text="Start point"/>
                  <TextBox Grid.Row="0" Grid.Column="1" Text="{Binding Path.Data.StartPoint}"/>

                  <TextBlock Grid.Row="1" Grid.Column="0" Text="End point"/>
                  <TextBox Grid.Row="1" Grid.Column="1" Text="{Binding Path.Data.EndPoint}"/>
                </Grid>
              </DataTemplate>

              <DataTemplate DataType="{x:Type local:XDrawingRectangle}">
                <Grid>
                  <Grid.Resources>
                    <Style TargetType="{x:Type TextBlock}">
                      <Setter Property="Margin" Value="3,1"/>
                      <Setter Property="VerticalAlignment" Value="Center"/>
                    </Style>
                    <Style TargetType="{x:Type TextBox}">
                      <Setter Property="Margin" Value="3,1"/>
                      <Setter Property="VerticalAlignment" Value="Center"/>
                    </Style>
                  </Grid.Resources>
                  <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" SharedSizeGroup="col0"/>
                    <ColumnDefinition Width="*" SharedSizeGroup="col1"/>
                  </Grid.ColumnDefinitions>
                  <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                  </Grid.RowDefinitions>

                  <TextBlock Grid.Row="0" Grid.Column="0" Text="Width"/>
                  <TextBox Grid.Row="0" Grid.Column="1" Text="{Binding Width}"/>

                  <TextBlock Grid.Row="1" Grid.Column="0" Text="Height"/>
                  <TextBox Grid.Row="1" Grid.Column="1" Text="{Binding Height}"/>

                  <TextBlock Grid.Row="2" Grid.Column="0" Text="Corner radius X"/>
                  <TextBox Grid.Row="2" Grid.Column="1" Text="{Binding Path.Data.RadiusX}"/>

                  <TextBlock Grid.Row="3" Grid.Column="0" Text="Corner radius Y"/>
                  <TextBox Grid.Row="3" Grid.Column="1" Text="{Binding Path.Data.RadiusY}"/>
                </Grid>
              </DataTemplate>

              <DataTemplate DataType="{x:Type local:XDrawingEllipse}">
                <Grid>
                  <Grid.Resources>
                    <Style TargetType="{x:Type TextBlock}">
                      <Setter Property="Margin" Value="3,1"/>
                      <Setter Property="VerticalAlignment" Value="Center"/>
                    </Style>
                    <Style TargetType="{x:Type TextBox}">
                      <Setter Property="Margin" Value="3,1"/>
                      <Setter Property="VerticalAlignment" Value="Center"/>
                    </Style>
                  </Grid.Resources>
                  <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" SharedSizeGroup="col0"/>
                    <ColumnDefinition Width="*" SharedSizeGroup="col1"/>
                  </Grid.ColumnDefinitions>
                  <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                  </Grid.RowDefinitions>

                  <TextBlock Grid.Row="0" Grid.Column="0" Text="Corner radius X"/>
                  <TextBox Grid.Row="0" Grid.Column="1" Text="{Binding Path.Data.RadiusX}"/>

                  <TextBlock Grid.Row="1" Grid.Column="0" Text="Corner radius Y"/>
                  <TextBox Grid.Row="1" Grid.Column="1" Text="{Binding Path.Data.RadiusY}"/>
                </Grid>
              </DataTemplate>

              <DataTemplate DataType="{x:Type local:XDrawingPath}">
                <Grid>
                  <Grid.Resources>
                    <DataTemplate DataType="{x:Type PathFigure}">
                      <Grid>
                        <Grid.ColumnDefinitions>
                          <ColumnDefinition Width="Auto"/>
                          <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                          <RowDefinition Height="Auto"/>
                          <RowDefinition Height="Auto"/>
                          <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>

                        <TextBlock Grid.ColumnSpan="2" Grid.Row="0" Text="Figure" HorizontalAlignment="Center" Margin="3"/>

                        <TextBlock Grid.Column="0" Grid.Row="1" Text="Is" Margin="3" VerticalAlignment="Center"/>
                        <StackPanel Grid.Column="1" Grid.Row="1" Orientation="Horizontal">
                          <CheckBox Content="closed" IsChecked="{Binding Path=IsClosed}" Margin="3"/>
                          <CheckBox Content="filled" IsChecked="{Binding Path=IsFilled}" Margin="3"/>
                        </StackPanel>

                        <TextBlock Grid.Column="0" Grid.Row="3" Text="Start point" Margin="3" VerticalAlignment="Center"/>
                        <TextBox Grid.Column="1" Grid.Row="3" Text="{Binding Path=StartPoint}" Margin="3"/>
                      </Grid>
                    </DataTemplate>

                    <DataTemplate DataType="{x:Type LineSegment}">
                      <Grid>
                        <Grid.ColumnDefinitions>
                          <ColumnDefinition Width="Auto"/>
                          <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                          <RowDefinition Height="Auto"/>
                          <RowDefinition Height="Auto"/>
                          <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>

                        <TextBlock Grid.ColumnSpan="2" Grid.Row="0" Text="Line segment" HorizontalAlignment="Center" Margin="3"/>

                        <ToolBar Grid.ColumnSpan="2" Grid.Row="1">
                          <RadioButton Content="L" ToolTip="Line segment" Tag="LineSegment" IsChecked="True"/>
                          <RadioButton Content="A" ToolTip="Arc segment" Tag="ArcSegment" IsChecked="False" Click="PathSegmentTypeChange_Click"/>
                          <RadioButton Content="B" ToolTip="Bezier segment" Tag="BezierSegment" IsChecked="False" Click="PathSegmentTypeChange_Click"/>
                          <RadioButton Content="B²" ToolTip="Quadratic bezier segment" Tag="QuadraticBezierSegment" IsChecked="False" Click="PathSegmentTypeChange_Click"/>
                        </ToolBar>

                        <TextBlock Grid.Column="0" Grid.Row="2" Text="Point" Margin="3" VerticalAlignment="Center"/>
                        <TextBox Grid.Column="1" Grid.Row="2" Text="{Binding Path=Point}" Margin="3"/>
                      </Grid>
                    </DataTemplate>

                    <DataTemplate DataType="{x:Type ArcSegment}">
                      <Grid>
                        <Grid.ColumnDefinitions>
                          <ColumnDefinition Width="Auto"/>
                          <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                          <RowDefinition Height="Auto"/>
                          <RowDefinition Height="Auto"/>
                          <RowDefinition Height="Auto"/>
                          <RowDefinition Height="Auto"/>
                          <RowDefinition Height="Auto"/>
                          <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>

                        <TextBlock Grid.ColumnSpan="2" Grid.Row="0" Text="Arc segment" HorizontalAlignment="Center" Margin="3"/>

                        <ToolBar Grid.ColumnSpan="2" Grid.Row="1">
                          <RadioButton Content="L" ToolTip="Line segment" Tag="LineSegment" IsChecked="False" Click="PathSegmentTypeChange_Click"/>
                          <RadioButton Content="A" ToolTip="Arc segment" Tag="ArcSegment" IsChecked="True"/>
                          <RadioButton Content="B" ToolTip="Bezier segment" Tag="BezierSegment" IsChecked="False" Click="PathSegmentTypeChange_Click"/>
                          <RadioButton Content="B²" ToolTip="Quadratic bezier segment" Tag="QuadraticBezierSegment" IsChecked="False" Click="PathSegmentTypeChange_Click"/>
                        </ToolBar>

                        <TextBlock Grid.Column="0" Grid.Row="2" Text="Point" Margin="3" VerticalAlignment="Center"/>
                        <TextBox Grid.Column="1" Grid.Row="2" Text="{Binding Path=Point}" Margin="3"/>

                        <TextBlock Grid.Column="0" Grid.Row="3" Text="Size" Margin="3" VerticalAlignment="Center"/>
                        <TextBox Grid.Column="1" Grid.Row="3" Text="{Binding Path=Size}" Margin="3"/>

                        <TextBlock Grid.Column="0" Grid.Row="4" Text="Large arc" Margin="3" VerticalAlignment="Center"/>
                        <CheckBox Grid.Column="1" Grid.Row="4" IsChecked="{Binding Path=IsLargeArc}" Margin="3"/>

                        <TextBlock Grid.Column="0" Grid.Row="5" Text="Sweep direction" Margin="3" VerticalAlignment="Center"/>
                        <ComboBox Grid.Column="1" Grid.Row="5" Margin="3"
                                  SelectedItem="{Binding Path=SweepDirection}" 
                                  ItemsSource="{Binding Source={StaticResource sweepDirectionValues}}"/>
                      </Grid>
                    </DataTemplate>

                    <DataTemplate DataType="{x:Type BezierSegment}">
                      <Grid>
                        <Grid.ColumnDefinitions>
                          <ColumnDefinition Width="Auto"/>
                          <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                          <RowDefinition Height="Auto"/>
                          <RowDefinition Height="Auto"/>
                          <RowDefinition Height="Auto"/>
                          <RowDefinition Height="Auto"/>
                          <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>

                        <TextBlock Grid.ColumnSpan="2" Grid.Row="0" Text="Bezier segment" HorizontalAlignment="Center" Margin="3"/>

                        <ToolBar Grid.ColumnSpan="2" Grid.Row="1">
                          <RadioButton Content="L" ToolTip="Line segment" Tag="LineSegment" IsChecked="False" Click="PathSegmentTypeChange_Click"/>
                          <RadioButton Content="A" ToolTip="Arc segment" Tag="ArcSegment" IsChecked="False" Click="PathSegmentTypeChange_Click"/>
                          <RadioButton Content="B" ToolTip="Bezier segment" Tag="BezierSegment" IsChecked="True"/>
                          <RadioButton Content="B²" ToolTip="Quadratic bezier segment" Tag="QuadraticBezierSegment" IsChecked="False" Click="PathSegmentTypeChange_Click"/>
                        </ToolBar>

                        <TextBlock Grid.Column="0" Grid.Row="2" Text="Point" Margin="3" VerticalAlignment="Center"/>
                        <TextBox Grid.Column="1" Grid.Row="2" Text="{Binding Path=Point3}" Margin="3"/>

                        <TextBlock Grid.Column="0" Grid.Row="3" Text="Control Point 1" Margin="3" VerticalAlignment="Center"/>
                        <TextBox Grid.Column="1" Grid.Row="3" Text="{Binding Path=Point1}" Margin="3"/>

                        <TextBlock Grid.Column="0" Grid.Row="4" Text="Control Point 2" Margin="3" VerticalAlignment="Center"/>
                        <TextBox Grid.Column="1" Grid.Row="4" Text="{Binding Path=Point2}" Margin="3"/>
                      </Grid>
                    </DataTemplate>


                    <DataTemplate DataType="{x:Type QuadraticBezierSegment}">
                      <Grid>
                        <Grid.ColumnDefinitions>
                          <ColumnDefinition Width="Auto"/>
                          <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                          <RowDefinition Height="Auto"/>
                          <RowDefinition Height="Auto"/>
                          <RowDefinition Height="Auto"/>
                          <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>

                        <TextBlock Grid.ColumnSpan="2" Grid.Row="0" Text="Quadratic bezier segment" HorizontalAlignment="Center" Margin="3"/>

                        <ToolBar Grid.ColumnSpan="2" Grid.Row="1">
                          <RadioButton Content="L" ToolTip="Line segment" Tag="LineSegment" IsChecked="False" Click="PathSegmentTypeChange_Click"/>
                          <RadioButton Content="A" ToolTip="Arc segment" Tag="ArcSegment" IsChecked="False" Click="PathSegmentTypeChange_Click"/>
                          <RadioButton Content="B" ToolTip="Bezier segment" Tag="BezierSegment" IsChecked="False" Click="PathSegmentTypeChange_Click"/>
                          <RadioButton Content="B²" ToolTip="Quadratic bezier segment" Tag="QuadraticBezierSegment" IsChecked="True"/>
                        </ToolBar>

                        <TextBlock Grid.Column="0" Grid.Row="2" Text="Point" Margin="3" VerticalAlignment="Center"/>
                        <TextBox Grid.Column="1" Grid.Row="2" Text="{Binding Path=Point2}" Margin="3"/>

                        <TextBlock Grid.Column="0" Grid.Row="3" Text="Control Point" Margin="3" VerticalAlignment="Center"/>
                        <TextBox Grid.Column="1" Grid.Row="3" Text="{Binding Path=Point1}" Margin="3"/>
                      </Grid>
                    </DataTemplate>
                  </Grid.Resources>
                  
                  <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                  </Grid.RowDefinitions>
                  
                  <ToolBar Grid.Row="0">
                    <Button Content="+ o" ToolTip="Add new point before selected" Click="AddNewPathPtBefore_Click"/>
                    <Button Content="o +" ToolTip="Add new point after selected" Click="AddNewPathPtAfter_Click"/>
                    <Separator/>
                    <Button Content="X" ToolTip="Delete selected point" Click="Button_Click"/>
                  </ToolBar>
                  
                  <ContentPresenter Grid.Row="1" Content="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}, Path=Drawing.SelectedControlPoint.Tag}"/>
                </Grid>
              </DataTemplate>
            </Border.Resources>

            <ContentPresenter Content="{Binding Path=.}"/>
          </Border>
        </StackPanel>
      </ScrollViewer>

      <Canvas Grid.Column="1" x:Name="canvas" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
              Background="White">
        <Path x:Name="controlPoints" Fill="White" Stroke="Blue" StrokeThickness="1" Opacity="0.5">
          <Path.Data>
            <GeometryGroup/>
          </Path.Data>
        </Path>
        <Path x:Name="selectedControlPoints" Fill="White" Stroke="Blue" StrokeThickness="2" Opacity="0.5">
          <Path.Data>
            <GeometryGroup/>
          </Path.Data>
        </Path>
        <Path x:Name="controlLines" Stroke="Blue" StrokeThickness="1" StrokeDashArray="5,5" Opacity="0.5">
          <Path.Data>
            <GeometryGroup/>
          </Path.Data>
        </Path>
      </Canvas>
    </Grid>
  </Grid>
</Window>
